package com.tjsinfo.tjsoa.addresslist.bo;

import java.util.ArrayList;
import java.util.List;

import com.tjsinfo.tjsoa.Dao.IJDBCDao;
import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.addresslist.dao.IAddressListSystemUserDAO;
import com.tjsinfo.tjsoa.addresslist.vo.AddressListSystemUser;

public class AddressListSystemUserBo implements IAddressListSystemUserBo {
	private IJDBCDao jdbcDao;
	private IAddressListSystemUserDAO listSystemUserDAO;
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.bo.IAddressListSystemUserBo#setListSystemUserDAO(com.tjsinfo.tjsoa.addresslist.dao.IAddressListSystemUserDAO)
	 */
	public void setListSystemUserDAO(IAddressListSystemUserDAO listSystemUserDAO) {
		this.listSystemUserDAO = listSystemUserDAO;
	}

	
	public void setJdbcDao(IJDBCDao jdbcDao) {
		this.jdbcDao = jdbcDao;
	}


	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.bo.IAddressListSystemUserBo#findByUserId(java.lang.String)
	 */
	public AddressListSystemUser findByUserId(Integer userId) {
		AddressListSystemUser user = new AddressListSystemUser();
		List list = new ArrayList();
		list = listSystemUserDAO.findByProperty("userId", userId);
		if (list.size()>0) {
			user = (AddressListSystemUser) list.iterator().next();
		}
		return user;
	}
	
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.bo.IAddressListSystemUserBo#save(com.tjsinfo.tjsoa.addresslist.vo.AddressListSystemUser)
	 */
	public void save(AddressListSystemUser user) {
		listSystemUserDAO.save(user);
	}
	
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.addresslist.bo.IAddressListSystemUserBo#update(com.tjsinfo.tjsoa.addresslist.vo.AddressListSystemUser)
	 */
	public void update(AddressListSystemUser user) {
		listSystemUserDAO.update(user);
	}
	
	public void updates(String id,String userId, String userName,String mobile,String email,String company,String sector,String duty,String companyPhone,String companyFax,String companyAddress,String companyPostal,String homeAddress,String homePostal,String homePhone,String birthday,String qq,String msn,String blog,String remarks) {
		String sql = "update dbo.t_addressList_User set userName='"+userName+"',mobile='"+mobile+"',email='"+email+"',company='"+company+"',sector='"+sector+"',duty='"+duty+"',companyPhone='"+companyPhone+"',companyFax='"+companyFax+"',companyAddress='"+companyFax+"',companyPostal='"+companyPostal+"',homeAddress='"+homeAddress+"',homePostal='"+homePostal+"',homePhone='"+homePhone+"',birthday='"+birthday+"',qq='"+qq+"',msn='"+msn+"',blog='"+blog+"',remarks='"+remarks+"' where user_id='"+id+"' and state='1'";
		String sql1 = "update dbo.t_addressList_systemUser set userName='"+userName+"',mobile='"+mobile+"',email='"+email+"',company='"+company+"',sector='"+sector+"',duty='"+duty+"',companyPhone='"+companyPhone+"',companyFax='"+companyFax+"',companyAddress='"+companyFax+"',companyPostal='"+companyPostal+"',homeAddress='"+homeAddress+"',homePostal='"+homePostal+"',homePhone='"+homePhone+"',birthday='"+birthday+"',qq='"+qq+"',msn='"+msn+"',blog='"+blog+"',remarks='"+remarks+"' where userId='"+userId+"'";
		if (birthday == null || "".equals(birthday)) {
			sql = "update dbo.t_addressList_User set userName='"+userName+"',mobile='"+mobile+"',email='"+email+"',company='"+company+"',sector='"+sector+"',duty='"+duty+"',companyPhone='"+companyPhone+"',companyFax='"+companyFax+"',companyAddress='"+companyFax+"',companyPostal='"+companyPostal+"',homeAddress='"+homeAddress+"',homePostal='"+homePostal+"',homePhone='"+homePhone+"',qq='"+qq+"',msn='"+msn+"',blog='"+blog+"',remarks='"+remarks+"' where user_id='"+id+"' and state='1'";
			sql1 = "update dbo.t_addressList_systemUser set userName='"+userName+"',mobile='"+mobile+"',email='"+email+"',company='"+company+"',sector='"+sector+"',duty='"+duty+"',companyPhone='"+companyPhone+"',companyFax='"+companyFax+"',companyAddress='"+companyFax+"',companyPostal='"+companyPostal+"',homeAddress='"+homeAddress+"',homePostal='"+homePostal+"',homePhone='"+homePhone+"',qq='"+qq+"',msn='"+msn+"',blog='"+blog+"',remarks='"+remarks+"' where userId='"+userId+"'";
		}
		jdbcDao.executeUpdate(sql);
		jdbcDao.executeUpdate(sql1);
		jdbcDao.closeStmt();
		jdbcDao.closeConn();
	}
}
